class PlayerScore2(val experience: Int, val level: Int) {
//    componentN()函数需要标记为 operator , 才可以在解构声明中使用
//componentN()函数的返回值类型必须与属性类型一致
    operator fun component1() = experience
    operator fun component2() = level
}

fun main() {
    val (x, y) = PlayerScore2(10, 20)

    println("$x, $y")
}

//=============解构就是将一个类对象中的参数拆开来，成为一个一个单独的变量，从而来使用这些单独的变量进行操作
data class Person1(var name:String,var age:Int){

}

fun function1(){
    var person:Person1 = Person1("Mike",20);
    var (name,age) = person;
    println("his name is $name,and his age is $age");
}

//========解构这个方式在平时使用的时候更多的是使用在集合的遍历或者说是对Map的遍历中。
fun function(){
    var person1 : Person1 = Person1("Mike",20);
    var person2 : Person1 = Person1("Jack",21);
    var person3 : Person1 = Person1("John",23);
    var person4 : Person1 = Person1("Helen",25);
    var person5 : Person1 = Person1("Dick",30);
    var list = listOf<Person1>(person1,person2,person3,person4,person5);
    for ((name,age) in list){
        print("name is $name,age is $age");
    }
}